package com.itboye.ihomebank.activity.qianyue;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.RepairPersenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

import java.util.Observable;
import java.util.Observer;

/**
 * 终止合同
 */
public class ZhongZhiHeTongActivity extends BaseOtherActivity implements Observer{
    View v_statusbar;
    ImageView close_icon;// 返回图片
    TextView add_shap_title_tv;// 标题
    EditText zhongzhi_et;
    TextView zhongzhi_ok;
    RepairPersenter persenter;
    String contractNo;
    String uid;
    @Override
    protected int layout_id() {
        return R.layout.zhong_zhi_hetong_activity;
    }

    @Override
    protected void onInitController() {

    }

    @Override
    protected void onInit() {
        setStatusBarHeight(v_statusbar);
        add_shap_title_tv.setText("终止合同");
        contractNo = getIntent().getStringExtra("contractNo");
        uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
        persenter=new RepairPersenter(this);

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close_icon:
                finish();
                break;
            case R.id.zhongzhi_ok:
                String str=zhongzhi_et.getText().toString();
                if(str.equals("")){
                    ByAlert.alert("请输入原因");
                    return;
                }
                persenter.ZhongZhiHeTong(uid,contractNo,zhongzhi_et.getText().toString());
                showProgressDialog("终止中,请稍后...", true);
                break;
            default:
                break;
        }
    }

    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            if (entity.getEventType() == RepairPersenter.zhongzhi_success) {
                ByAlert.alert(entity.getData());
                finish();
            }
            if (entity.getEventType() == RepairPersenter.zhongzhi_fail) {
                ByAlert.alert(entity.getData());
            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }
}
